import { Controller, Get, Query } from '@nestjs/common';
import { CaptchaDto } from './captcha.dto';
import { createText, createMath } from 'src/utils/captcha';
import { Result } from '../../result/Result';

@Controller('/captcha')
export class CaptchaController {
  @Get()
  GenerateCaptcha(@Query() { type }: CaptchaDto) {
    const captchaImg = type === 'text' ? createText() : createMath();
    return Result.Ok(
      {
        captchaImg: captchaImg.data,
        uuid: captchaImg.uuid,
      },
      '获取验证码成功',
    );
  }
}
